exports.searchOrganizationUser = function (req, res) {

    var restfulParams = req.routeInfo.restfulParams;
    //最终结果
    var resultData = {};
    //注册后的用户ID
    var userId = 0;
    //任务流创建
    async.waterfall([
        function (cb) {
            R.SEND_HTTP(
                req,
                {
                    url: CORE_APIConfig.coreAPI.searchUserOrganization,
                    method: 'POST',
                    data: {
                        fields: ["u_username", "ou_uid", "ou_name", "openid", "ou_phone"].join(",")
                    }
                },
                function (err, data) {
                    //判断是否有错误信息
                    if (err) {
                        console.log(data);
                        return cb(err, data);
                    }
                    console.log(data.data);
                    resultData.userInfo = data.data;
                    cb();
                }
            );

        },
        function (cb) {

            var userInfo = resultData.userInfo;

            var tasks = [];

            if (userInfo.length > 0) {
                userInfo.forEach(function (item, i) {
                    tasks.push(function (cb) {

                        R.SEND_HTTP(
                            req, {
                                url: CORE_APIConfig.coreAPI.sendCodeSms,
                                method: 'POST',
                                data: {
                                    phone: item.ou_phone,
                                    type: 7,
                                    username: item.u_username,
                                }
                            },
                            function (err, data) {
                                cb();

                            }
                        );

                    });
                });
            } else {
                cb()
            }

            async.waterfall(tasks, cb);
        },

    ], function (err, result) {

        //返回最终拼接结果
        RES.response(res, true, resultData);

    });

}